package com.fang.gateway.security.handler;

import com.fang.common.common.CommonResult;
import com.fang.common.exception.ExceptionCode;
import com.fang.common.util.CommonResultUtil;
import com.fang.gateway.security.utils.HandlerUtils;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.server.authorization.ServerAccessDeniedHandler;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @Description 权限拒绝处理逻辑
 * @Author Bernie
 * @Date 2024/4/23 10:45
 **/
@Component
public class FluxAccessDeniedHandler implements ServerAccessDeniedHandler {
    /**
     * Description: 暂无权限返回结果
     *
     * @param exchange:
     * @param denied:
     * @Author: Bernie_fang
     * @Since: 2025/3/9 21:57
     * @return: reactor.core.publisher.Mono<java.lang.Void>
     **/
    @Override
    public Mono<Void> handle(ServerWebExchange exchange, AccessDeniedException denied) {
        CommonResult result = CommonResultUtil.failed(ExceptionCode.PERMISSION_DENIED);
        return HandlerUtils.writeWith(exchange, result);
    }

}
